using System;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace WinformToolkit.Drawing
{
    /// <summary>
    /// Triangle graphic object
    /// </summary>
    public class DrawTriangle : WinformToolkit.Drawing.DrawRectangle
    {
        public override DrawArea.DrawToolType Type => DrawArea.DrawToolType.Triangle;

        public DrawTriangle(PropertiesGraphics properties) :
            base(properties)
        {
            Initialize();
        }

        /// <summary>
        /// Clone this instance
        /// </summary>
        public override DrawObject Clone()
        {
            DrawTriangle drawTriangle = new DrawTriangle(null);

            FillDrawObjectFields(drawTriangle);
            return drawTriangle;
        }

        public override void Draw(DrawingContext dc)
        {
            Graphics g = dc.Graphics;

            g.SmoothingMode = SmoothingMode.AntiAlias;

            Pen pen = new Pen(Color, PenWidth);
            PointF[] pts = { new PointF(this.rectangle.X, this.rectangle.Y + this.rectangle.Height),
                            new PointF(this.rectangle.X + this.rectangle.Width / 2, this.rectangle.Y),
                            new PointF(this.rectangle.X + this.rectangle.Width, this.rectangle.Y + this.rectangle.Height) };
            // version 1
            // use Graphics.DrawLine(int x, int y)
            /* 
             * pen.StartCap = LineCap.Round;
             * pen.EndCap = LineCap.Round;
             * g.DrawLine(pen, pts[0], pts[1]);
             * g.DrawLine(pen, pts[1], pts[2]);
             * g.DrawLine(pen, pts[0], pts[2]);
             */

            // version 2
            // use Graphics.DrawLines(Pen pen, Point[] points)
            /* 
             * g.DrawLines(pen, pts);
             */

            // version 3
            // use Graphics.DrawPath(Pen pen, GraphicsPath path)
            /* 
             * GraphicsPath path = new GraphicsPath();
             * path.AddLines(pts);
             * g.DrawPath(pen, path);
             */

            // version 4
            // use Graphics.DrawPolygon(Pen pen, Point[] points)
            g.DrawPolygon(pen, pts);

            pen.Dispose();
        }
    }
}
